package com.facebank.usersupport.controller;

import com.facebank.usersupport.model.Associator;
import com.facebank.usersupport.model.RestModel;
import com.facebank.usersupport.service.IAgentService;
import com.facebank.usersupport.util.ImgSaveUtil;
import com.facebank.usersupport.util.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Auther: yaozun
 * @Date: 2018/4/3 0003 09:08
 * @Description:
 */
@RestController
public class AgentController {
    @Autowired
    private IAgentService agentService;
    @RequestMapping("/agent/add")
    public RestModel add(Associator associator, HttpSession session) {
        return agentService.add(associator,session);
    }

    @RequestMapping("/agent/list")
    public RestModel list(@RequestParam(required = false, defaultValue = "1") int pageNo,
                          @RequestParam(required = false, defaultValue = "6") int length,
                          String associatorName, String phone, Short status , String starttime, String endtime,HttpSession session){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Long startTime = TimeUtil.StringToLong(starttime,sdf);
        Long endTime = TimeUtil.StringToLong(endtime,sdf);
        return agentService.list(pageNo, length, associatorName, phone, status, startTime, endTime ,session);
    }

    /**
     * 收益记录
     */
    @RequestMapping("/agent/profit_details")
    public RestModel profitDetails(@RequestParam(required = false, defaultValue = "1") int start,
                                   @RequestParam(required = false, defaultValue = "6") int length,
                                   String phone ,Long datetimeStart, Long datetimeEnd,HttpSession session, String draw){
        int pageNo = start / length + 1;
        return agentService.profit(phone,datetimeStart,datetimeEnd,session,pageNo,length,draw);
    }
}
